package com.jic.market.impl;


import com.jic.common.base.vo.Page;
import com.jic.common.base.vo.PageResult;
import com.jic.market.common.util.ListUtils;
import com.jic.market.entity.AllocationModel;
import com.jic.market.mapper.AllocationMapper;
import com.jic.market.response.manager.allocation.AllocationQueryResponse;
import com.jic.market.service.AllocationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 *  分摊管理表 服务类
 *
 * @author xuyongliang
 * @since 2020-03-15
 */
@Service
public class AllocationServiceImpl implements AllocationService {

    @Autowired
    private AllocationMapper modelMapper;

    /**
     * 分摊管理表 新增
     * @param modelEntity
     */
    @Override
    public Integer allocationAdd(AllocationModel modelEntity){
        return modelMapper.allocationAdd(modelEntity);
    }

    /**
     * 分摊管理表 编辑
     * @param modifyEntity
     * @param whereCondition
     */
    @Override
    public Integer allocationEdit(AllocationModel modifyEntity, AllocationModel whereCondition){
        return modelMapper.allocationEdit(modifyEntity, whereCondition);
    }

    /**
     * 分摊管理表 删除
     * @param \
     */
    @Override
    public Integer allocationDelete(Long id){
        return modelMapper.allocationDeleteById(id);
    }

    /**
     * 分摊管理表 查询详情
     * @param
     */
    @Override
    public AllocationModel allocationQuery(AllocationModel modelEntity){
        return modelMapper.allocationQuery(modelEntity);
    }

    /**
     * 分摊管理表 分页查询
     * @param
     */
    @Override
    public PageResult<AllocationQueryResponse> allocationQueryPageList(AllocationModel modelEntity, Page pageQuery){
        //计算下标
        int startIndex = (pageQuery.getStart() - 1) * pageQuery.getLimit();
        List<AllocationModel> list = modelMapper.allocationQueryPageList(startIndex, pageQuery.getLimit(), modelEntity);
        List<AllocationQueryResponse> rows =ListUtils.entityListToModelList(list, AllocationQueryResponse.class);
        long count = modelMapper.allocationQueryPageCount(modelEntity);
        PageResult<AllocationQueryResponse> pageResult = new PageResult<>();
        pageResult.setRows(rows);
        pageResult.setTotal(count);
        return pageResult;
    }

}